const { PrismaClient } = require('@prisma/client');

async function updateConfirmedStatus() {
  const prisma = new PrismaClient();
  
  try {
    console.log('开始更新交易confirmed状态...');
    
    // 更新所有existing transactions的confirmed字段为true
    const result = await prisma.transaction.updateMany({
      where: {
        confirmed: null, // 或者可以不加where条件来更新所有记录
      },
      data: {
        confirmed: true,
      },
    });
    
    console.log(`✅ 成功更新了 ${result.count} 条交易记录的confirmed状态`);
    
    // 验证更新结果
    const confirmedCount = await prisma.transaction.count({
      where: { confirmed: true }
    });
    
    const totalCount = await prisma.transaction.count();
    
    console.log(`📊 数据库统计: ${confirmedCount}/${totalCount} 条交易已确认`);
    
  } catch (error) {
    console.error('❌ 更新失败:', error);
  } finally {
    await prisma.$disconnect();
  }
}

updateConfirmedStatus(); 